﻿using System.Windows;
using System.Windows.Controls;
using JDKD.BMCS.Business;
using JDKD.BMCS.Instruction;
using NutShell.DesignPattern;

namespace JDKD.BMCS.AppUI
{
        /// <summary>
        /// FrontAeraPage.xaml 的交互逻辑
        /// </summary>
        public partial class CameraPage : Page
        {
                public CameraPage()
                {
                        InitializeComponent();
                }

                #region 字段

                private BusinessCache cache = Singleton<BusinessCache>.Instance;

                #endregion 字段

                #region 属性

                #endregion 属性

                #region 方法

                private void Page_Loaded(object sender, System.Windows.RoutedEventArgs e)
                {
                        RootGrid.DataContext = cache;
                }

                private void ApertureIncreaseButton_MouseDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
                {
                        if (!cache.IsLogined)
                        {
                                MessageBox.Show("请登录后执行此操作");
                                return;
                        }

                        if (cache.CurrentCamera == null)
                        {
                                MessageBox.Show("请选择摄像机");
                                return;
                        }
                        SerialPortCommunication.SendApertureInstruction(cache.CurrentCamera.Id, true);
                }

                private void ApertureDecreaseButton_MouseDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
                {
                        if (!cache.IsLogined)
                        {
                                MessageBox.Show("请登录后执行此操作");
                                return;
                        }
                        if (cache.CurrentCamera == null)
                        {
                                MessageBox.Show("请选择摄像机");
                                return;
                        }
                        SerialPortCommunication.SendApertureInstruction(cache.CurrentCamera.Id, false);
                }

                private void FocalDistanceIncreaseButton_MouseDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
                {
                        if (!cache.IsLogined)
                        {
                                MessageBox.Show("请登录后执行此操作");
                                return;
                        }
                        if (cache.CurrentCamera == null)
                        {
                                MessageBox.Show("请选择摄像机");
                                return;
                        }
                        SerialPortCommunication.SendFocalDistanceInstruction(cache.CurrentCamera.Id, true);
                }

                private void FocalDistanceDecreaseButton_MouseDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
                {
                        if (!cache.IsLogined)
                        {
                                MessageBox.Show("请登录后执行此操作");
                                return;
                        }
                        if (cache.CurrentCamera == null)
                        {
                                MessageBox.Show("请选择摄像机");
                                return;
                        }
                        SerialPortCommunication.SendFocalDistanceInstruction(cache.CurrentCamera.Id, false);
                }

                private void FocusIncreaseButton_MouseDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
                {
                        if (!cache.IsLogined)
                        {
                                MessageBox.Show("请登录后执行此操作");
                                return;
                        }
                        if (cache.CurrentCamera == null)
                        {
                                MessageBox.Show("请选择摄像机");
                                return;
                        }
                        SerialPortCommunication.SendFocusInstruction(cache.CurrentCamera.Id, true);
                }

                private void FocusDecreaseButton_MouseDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
                {
                        if (!cache.IsLogined)
                        {
                                MessageBox.Show("请登录后执行此操作");
                                return;
                        }
                        if (cache.CurrentCamera == null)
                        {
                                MessageBox.Show("请选择摄像机");
                                return;
                        }
                        SerialPortCommunication.SendFocusInstruction(cache.CurrentCamera.Id, false);
                }

                private void PushButton_Click(object sender, System.Windows.RoutedEventArgs e)
                {
                        if (!cache.IsLogined)
                        {
                                MessageBox.Show("请登录后执行此操作");
                                return;
                        }
                        if (cache.CurrentCamera == null)
                        {
                                MessageBox.Show("请选择摄像机");
                                return;
                        }

                        new PushOperation(cache.CurrentCamera.Group.Id, true).Run();

                        
                }

                private void ResetButton_Click(object sender, System.Windows.RoutedEventArgs e)
                {
                        if (!cache.IsLogined)
                        {
                                MessageBox.Show("请登录后执行此操作");
                                return;
                        }
                        if (cache.CurrentCamera == null)
                        {
                                MessageBox.Show("请选择摄像机");
                                return;
                        }

                        new PushOperation(cache.CurrentCamera.Group.Id, false).Run();
                }

                #endregion 方法
        }
}